﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyCuaHangBanMayTinh.He_Thong_Xu_Ly;
using System.Data;

namespace QuanLyCuaHangBanMayTinh.He_Thong_Du_Lieu
{
    class QuanLyNhanVienDAO
    {
        static public DataTable SelectTLAll()
        {
            string sql = "select * from NHANVIEN";
            DataTable dt = DataAccess.ExecQuery(sql);
            return dt;
        }
        static public void Insert(QuanLyNhanVienDTO nv)
        {
            string sql = "insert into NHANVIEN(HoTenNhanVien,NgaySinh,DiaChi,DienThoai,BangCap,BoPhan,ChucVu) values('" + nv.HoTenNhanVien + "','" + nv.NgaySinh + "','" + nv.DiaChi + "','" + nv.DienThoai + "','" + nv.BangCap + "','" + nv.BoPhan + "','" + nv.ChucVu + "')";
            DataAccess.ExecNonQuery(sql);
        }
        static public void Update(QuanLyNhanVienDTO nv)
        {
            string sql = "update NHANVIEN set TenNhanVien = '" + nv.HoTenNhanVien + "' where MaNhanVien = '" + nv.MaNhanVien;
            DataAccess.ExecNonQuery(sql);
        }
        static public void Delete(QuanLyNhanVienDTO nv)
        {
            {
                string sql = "delete from NHAVIEN where MaNhanVien = " + nv.MaNhanVien;
                DataAccess.ExecNonQuery(sql);
            }
        }
        static public QuanLyNhanVienDTO SelectTLByName(string name)
        {
            string sql = "select * from NHANVIEN where HoTenNhanVien = '" + name + "'";
            DataTable dt = DataAccess.ExecQuery(sql);
            if (dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                QuanLyNhanVienDTO nv = new QuanLyNhanVienDTO();
                nv.HoTenNhanVien = dt.Rows[0].ItemArray[1].ToString();

                return nv;
            }
        }
    }
}
